home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / dev / lang / python020.lha / python / lib / test / test_select.py < prev    next >
Text File  |  1995-10-22  |  500b  |  24 lines

  1. # Testing select module
  2.  
  3. def test():
  4.     import select
  5.     import os
  6.     cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do date; sleep 3; done'
  7.     p = os.popen(cmd, 'r')
  8.     for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
  9.         print 'timeout =', tout
  10.         rfd, wfd, xfd = select.select([p], [], [], tout)
  11.         print rfd, wfd, xfd
  12.         if (rfd, wfd, xfd) == ([], [], []):
  13.             continue
  14.         if (rfd, wfd, xfd) == ([p], [], []):
  15.             line = p.readline()
  16.             print `line`
  17.             if not line:
  18.                 print 'EOF'
  19.                 break
  20.             continue
  21.         print 'Heh?'
  22.  
  23. test()
  24.